<style>
    #layui-upload-box li{
        width: 120px;
        height: 100px;
        float: left;
        position: relative;
        overflow: hidden;
        margin-right: 10px;
        border:1px solid #ddd;
    }
    #layui-upload-box li img{
        width: 100%;
    }
    #layui-upload-box li p{
        width: 100%;
        height: 22px;
        font-size: 12px;
        position: absolute;
        left: 0;
        bottom: 0;
        line-height: 22px;
        text-align: center;
        color: #fff;
        background-color: #333;
        opacity: 0.6;
    }
    #layui-upload-box li i{
        display: block;
        width: 20px;
        height:20px;
        position: absolute;
        text-align: center;
        top: 2px;
        right:2px;
        z-index:999;
        cursor: pointer;
    }
</style>
<script>
    layui.use(['form', 'layedit', 'laydate'], function(){
        var form = layui.form
            ,layer = layui.layer
            ,layedit = layui.layedit
        //创建一个编辑器
        var editIndex = layedit.build('LAY_demo_editor');
        form.verify({//自定义验证规则
            internal_name:function(value){
                if(value.length ==0){
                    return '请输入内部名称';
                }
            },
            title:function(value){
                if(value.length ==0){
                    return '请输入标题';
                }
            },
            abstract:function(value){
                if(value.length ==0){
                    return '请输入摘要';
                }
            },
            hit_type: function(value){
                if(value==''){
                    return '请选择命中类型';
                }
            },
            hit_content: function(value){
                if(value.length ==0){
                    return '请输入命中内容';
                }
            },
            thumb: function(value){
                if(value.length ==0){
                    return '请输入上传图片';
                }
            },
            weight: function(value){
                if(value.length ==0){
                    return '请输入权重';
                }
            },
            start_time: function(value){
                if(value.length == 0){
                    return '请选择开始时间';
                }
            },
            end_time: function(value){
                if(value.length == 0){
                    return '请选择结束时间';
                }
            }
            ,content: function(value){
                layedit.sync(editIndex);
            }
        });
        form.on('select(change_hit_type)', function(data){
            $('#hit_content').val('');
        });
        form.on('submit(operate_position_filter)', function(data){
            $(this).text('提交中...');
            if($(this).hasClass('layui-btn-disabled'))
                $(this).attr('disabled','disabled');
            $(this).addClass('layui-btn-disabled');
        });
    });
    layui.use('laydate', function(){
        var laydate = layui.laydate;
        //日期时间选择器
        laydate.render({
            elem: '#start_time'
            ,type: 'datetime'
        });
        laydate.render({
            elem: '#end_time'
            ,type: 'datetime'
        });
    });
    layui.use(['upload'],function () {
        var upload = layui.upload
        //普通图片上传
        var uploadInst = upload.render({
            elem: '#uploadPic'
            ,url: '{{ route("uploadImg") }}'
            ,multiple: false
            ,data:{"_token":"{{ csrf_token() }}"}
            ,before: function(obj){
                obj.preview(function(index, file, result){
                    $('#layui-upload-box').html('<li><img src="'+result+'" /><p>上传中</p></li>')
                });
            }
            ,done: function(res){
                //如果上传失败
                if(res.code == 0){
                    $("#thumb").val(res.url);
                    $('#layui-upload-box li p').text('上传成功');
                }
                return layer.msg(res.msg);
            }
        });
    });
    $('#hit_content').click(function () {
        var hit_type =$("#hit_type").val();
        if(hit_type=='goods_detail'){
            var url="{{route('admin.goods_list')}}";
            var title='选择商品';
        }else if(hit_type=='goods_cate'){
            var url="{{route('admin.goods_category')}}";
            var title='选择商品分类';
        }else if(hit_type=='activity'){
            var url="{{route('admin.activity')}}";
            var title='选择活动';
        }else{
            return false;
        }
        layer.open({
            type: 2,
            title: title,
            shadeClose: true,
            shade: 0.8,
            area: ['90%', '90%'],
            content: url //iframe的url
        });
    })
</script>